$(document).ready(function(){  
	$("#functionNav").attr("href",navAddr);

	getUserRight();
	var roleid = userInfo.roleid;
	if(roleid.indexOf("zerenbaoguanyuan")>-1){
		$("#add_btn").show();
		$("#delete_btn").show();
	}else{
		$("#add_btn").hide();
		$("#delete_btn").hide();
	}
	dxjbJson = ajaxResult("get",false,ProjectName+"/sysmanage.getIdAndNameInjb.do", {"tableName":'jb_xfjb'});
	dxjbJson = dxjbJson.rows;
	loadSelect("#dxjb",dxjbJson,'id','name');
	loadSelect("#dx_dxjb",dxjbJson,'id','name');
	
	dxyyJson = ajaxResult("get",false,ProjectName+"/sysmanage.getIdAndNameInjb.do", {"tableName":'jb_xfyy'});
	dxyyJson = dxyyJson.rows;
	loadSelect("#dxyy",dxyyJson,'id','name');
	loadSelect("#dx_dxyy",dxyyJson,'id','name');

	
	//获取并填充保管部门
	var bgbmJson = ajaxResult("get",false,ProjectName+"/sysmanage.getIdAndNameInjb.do",{'tableName':'jb_bgbm'});
	loadSelect("#bgbm",bgbmJson.rows,'id','name');
	
	//根据保管部门id获取并填充库房
	$("#bgbm").change(function(){
		var bgbmid = $(this).val();
		if(bgbmid !=null && bgbmid !=''){
			var kfJson = ajaxResult("get",false,ProjectName+"/sysmanage.getkfIdNameBybgbmId.do",{'bgbmId':bgbmid});
			loadSelect("#szkf",kfJson.rows,'kfid','kfmc');
		}
	});
	  
	var params =$("#form1").serializeObject();
    //初始化出退库单据Table
	createTable('#waitingrepairTable',ProjectName+'/colrepair.getColWaitingRepairList.do','id',dxcpTitle,params);	
	//点击查询按钮
	 $("#search_btn").click(function(){
		 refreshTable('#waitingrepairTable','#form1');
	 });
	 $("#add_btn").click(function(){
		 window.location.href = "dxcpDetail.html";
	 });
	 $("#delete_btn").click(function(){
		 var ids = selDataIds("#waitingrepairTable");
		 if(ids.length == 0){
			 alertFunc("请选择记录！");
			 return false;
		 }
		 bootbox.setLocale("zh_CN");
		 bootbox.confirm("您确定删除？",function(r){
			 if(r){
				 var detail = ajaxResult("get",false,ProjectName+"/colrepair.delColWaitingRepair.do",{"id":ids+""});
				 if(detail.status=="ok"){
					 alertFunc("删除成功");
					 refreshTable('#waitingrepairTable','#form1');
				 }else{
					 alertFunc("删除失败");
				 }
			 }
		 });

	 });
	 $("#save_btn").click(function(){
		 $("#lrrid").val(userInfo.userid);
		 $("#lrrmc").val(userInfo.username);
		 $("#lrsj").val(nowDate());
		 var params =$("#form_dxxx").serializeObject();
		 var detail = ajaxResult("get",false,ProjectName+"/colrepair.saveColWaitingRepair.do",params);
		 if(detail.status=="ok"){
			 alert("保存成功");
			 $("#dxxxModal").modal('hide');
			 refreshTable('#waitingrepairTable','#form1');
		 }else{
			 alert("保存失败")
		 }
			
	 });
})
function showDetail(id){
	var detail = ajaxResult("get",false,ProjectName+"/colrepair.getColWaitingRepairDetailById.do",{"id":id});
	 //填充藏品信息到表单
	 if(detail.status=="ok"){
		 loadData("#form_dxxx",detail.data); 
		 if(detail.data.editable==true){//可编辑
			 $("#save_btn").show();
			 $('#remark').removeAttr("readonly");
			 $('#dx_dxyy').removeAttr("disabled");
			 $('#dx_dxjb').removeAttr("disabled");
		 }else{//只读
			 $("#save_btn").hide();
			 $('#remark').attr("readonly","readonly");
			 $('#dx_dxyy').attr("disabled","disabled");
			 $('#dx_dxjb').attr("disabled","disabled");
		 }
		 $("#dxxxModal").modal('show');
	 }
}
var dxcpTitle = [{
    checkbox: true,
    formatter : function(value, row, index) {
    	if (row.editable == false)
            return {
                disabled : true,//设置是否可用
                checked : false//设置选中
            };
        else
            return {
            disabled : false,//设置是否可用
            checked : false//设置选中
        };
	}
}, {
	field: 'zdjh',
	title: '藏品总登记号',
	formatter: function(value, row, index) {
		return '<a href="#" onclick="showDetail('+row.id+')">'+value+'</a>';
	}
},{
	field: 'flh',
	title: '分类号'
},{
	field: 'cpmc',
	title: '藏品名称',
	formatter: function(value, row, index) {
		return '<a href="#" onclick="showDetail('+row.id+')">'+value+'</a>';
	}
},{
	field: 'cpfl1',
	title: '藏品分类'
},{
	field: 'dxjb',
	title: '待修级别'
},{
	field: 'szkf',
	title: '所在库房'
},{ 
	field: 'zrbgy',
	title: '责任保管员'
},{
	field: 'lrsj',
	title: '录入时间'
}]